;(function  () {
	var valid = function  () {
		var txtName;
		var txtPwd;
		var txtAgain;
		var txtbir;
		var txtTel;
		var txtEmail;
		var btnSubmit;
		
		//正则表达式
		var regName=/^(\w{2,12})$/;
		var regPwd=/^(\w{6,12})$/;
		var regbir = /^19[7-9][0-9]|2000-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/;
		var regEmail=/^(\w+(\.\w+)?@\w+(\.\w+)?\.(com|cn|edu|org|net))$/;
		var regTel=/^(1[3578][0-9]{9})$/;
		
		var loadEvent = function  () {
			btnSubmit.onclick = validHandler;
		}
		
		var  validHandler= function  () {
			if (!regName.test(txtName.value)) {
				alert("用户名不允许为空");
				return;
			}
			if (!regPwd.test(txtPwd.value)) {
				alert("密码必须是6-12位");
				return;
			}
			if (txtPwd.value !==txtAgain.value) {
				alert("重复密码与密码不一致");
				return;
			}
			if (!regbir.test(txtbir.value)) {
				alert("请输入正确的生日！");
				return;
			}
			if (!regEmail.test(txtEmail.value)) {
				alert("请输入有效的邮箱格式");
				return;
			}
			if (!regTel.test(txtTel.value)) {
				alert("请输入有效的联系方式");
				return;
			}
			alert("验证通过！");
		}
		
		
		return{
			init:function  () {
				txtName=document.getElementById("username");
				txtPwd=document.getElementById("password");
				txtAgain=document.getElementById("pwdagain");
				txtbir=document.getElementById("bir");
				txtTel=document.getElementById("tel");
				txtEmail=document.getElementById("email");
				btnSubmit=document.getElementById("btnSubmit");
				
				loadEvent();
			}
		}
	}();
	valid.init();
})();